<script setup lang='ts'>
import { useCountdown } from '@/hooks'
import dayjs from 'dayjs'

// 计算距离本周五结束还有多久
function getFridayEndTime() {
  const today = dayjs()
  const dayOfWeek = today.day() // 今天是星期几（0-6，0为周日）
  const daysUntilFriday = (5 - dayOfWeek + 7) % 7 // 计算到本周五还有几天
  const fridayEndTime = today.add(daysUntilFriday, 'day').endOf('day')
  return fridayEndTime.toISOString()
}

const countdownToFridayEnd = useCountdown(getFridayEndTime())

// 计算距离本月末还有多久
function getEndOfMonthTime() {
  const today = dayjs()
  const endOfMonth = today.endOf('month')
  return endOfMonth.toISOString()
}

const countdownToEndOfMonth = useCountdown(getEndOfMonthTime())
</script>

<template>
  <div>
    <p>
      距离本周五结束还有:
      {{ countdownToFridayEnd.days }}天
      {{ countdownToFridayEnd.hours }}小时
      {{ countdownToFridayEnd.minutes }}分钟
      {{ countdownToFridayEnd.seconds }}秒
    </p>
    <p>
      距离本月末还有:
      {{ countdownToEndOfMonth.days }}天
      {{ countdownToEndOfMonth.hours }}小时
      {{ countdownToEndOfMonth.minutes }}分钟
      {{ countdownToEndOfMonth.seconds }}秒
    </p>
  </div>
</template>
